package com.docker.manege.server;

import com.docker.core.constant.APPIDConstant;
import com.docker.core.mvc.APPID;
import com.docker.core.mvc.Remark;
import com.docker.core.mvc.controller.BaseAPIController;
import com.jfinal.aop.Inject;
import com.jfinal.kit.Okv;
import com.jfinal.kit.StrKit;

/**
 * @Author ldl
 * @Create 2020/12/02 002 14:52
 */
@Remark("docker服务器管理")
@APPID(APPIDConstant.dum_web)
public class DockerServerController extends BaseAPIController {

    @Inject
    private DockerServerService dockerServerService;

    /**
     * @Param: []
     * @return: TODO
     * @Author: ldl
     * @Create: 2020/12/31 031 11:33
     */
    @Remark("分页列表")
    public void paginate() {
        renderAPISuccess(dockerServerService.paginate(buildFilter(), getPageNum(), getPageSize()));
    }

    private Okv buildFilter() {
        Okv cond = Okv.create()
                .set("doc.status_flag = ", "1")
                .set("doc.docker_port = ", getPara("docker_port"));
        if (StrKit.notBlank(getPara("docker_host"))) {
            cond.set("doc.docker_host like ", "%" + getPara("docker_host") + "%");
        }
        if (StrKit.notBlank(getPara("docker_name"))) {
            cond.set("doc.docker_name like ", "%" + getPara("docker_name") + "%");
        }
        return Okv.by("cond", cond);
    }

    /**
     * @Param: []
     * @return: TODO
     * @Author: ldl
     * @Create: 2020/12/31 031 11:33
     */
    @Remark("下拉查找")
    public void look() {
        renderAPISuccess(dockerServerService.look(buildFilter()));
    }

    /**
     * @Param: []
     * @return: TODO
     * @Author: ldl
     * @Create: 2020/12/31 031 11:33
     */
    @Remark("新增")
    public void save() {
        renderAPI(dockerServerService.save(getBean(DockerServerBean.class, ""), getUserId()));
    }

    /**
     * @Param: []
     * @return: TODO
     * @Author: ldl
     * @Create: 2020/12/31 031 11:33
     */
    @Remark("详情")
    public void detail() {
        renderAPISuccess(dockerServerService.detail(getPara("server_id")));
    }

    /**
     * @Param: []
     * @return: TODO
     * @Author: ldl
     * @Create: 2020/12/31 031 11:33
     */
    @Remark("修改")
    public void update() {
        renderAPI(dockerServerService.update(getBean(DockerServerBean.class, ""), getUserId()));
    }

    /**
     * @Param: []
     * @return: TODO
     * @Author: ldl
     * @Create: 2020/12/31 031 11:33
     */
    @Remark("删除")
    public void delete() {
        renderAPI(dockerServerService.delete(getPara("server_id"), getUserId()));
    }

    /**
     * @Param: []
     * @return: TODO
     * @Author: ldl
     * @Create: 2020/12/31 031 11:34
     */
    @Remark("连接")
    public void connect() {
        renderAPI(dockerServerService.connect(getPara("token"), getPara("server_id")));
    }

    /**
     * @Param: []
     * @return: TODO
     * @Author: ldl
     * @Create: 2021/01/04 004 15:05
     */
    @Remark("断开")
    public void disconnect() {
        renderAPI(dockerServerService.disconnect(getPara("token"), getPara("server_id")));
    }

    /**
     * @Param: []
     * @return: TODO
     * @Author: ldl
     * @Create: 2021/01/22 022 09:29
     */
    @Remark("控制台")
    public void console() {
        //只做前端权限判断，不做逻辑处理
        renderAPI(true);
    }

}
